using System;
using System.Composition;
using FluentNHibernate.Cfg.Db;

namespace Ant.BasicPlugIn.Data.Providers
{
    [Export("MySql", typeof(IDataServicesProvider))]
    internal class MySqlDataServicesProvider : AbstractDataServicesProvider
    {
        private readonly string _connectionString;

        public MySqlDataServicesProvider()
        {
            _connectionString = Parameter;
        }

        public static string ProviderName
        {
            get { return "MySql"; }
        }

        public override IPersistenceConfigurer GetPersistenceConfigurer(bool createDatabase)
        {
            var persistence = MySQLConfiguration.Standard;
            if (string.IsNullOrEmpty(Parameter))
            {
                throw new ArgumentException("The connection string is empty");
            }
            persistence = persistence.ConnectionString(Parameter);
            return persistence;
        }
    }
}